<template>
  <h4>当前的求和为：{{ sum }}</h4>
  <button @click="sum++">点我x加一</button>
  <hr>
  <h2>姓名：{{ name }}</h2>
  <h2>年龄：{{ age }}</h2>
  <h2>薪资：{{ job.j1.salary }}</h2>
  <button @click="name += '~'">修改姓名</button>
  <button @click="age ++ ">增长年龄</button>
  <button @click="job.j1.salary ++ ">张薪</button>
</template>

<script>
import {ref, reactive, toRefs} from 'vue'
// import { readonly, shallowReadonly} from 'vue'

export default {

  setup() {
    // 数据
    let sum = ref(0)
    let person = reactive({ // 只考虑第一层数据的响应式
      name: 'achao',
      age: 18,
      job: {
        j1: {
          salary: 100
        }
      }
    })

    // 使数据变成只读
    // person = readonly(person)

    // 使数据变成浅只读
    // person = shallowReadonly(person)

    // 返回一个对象
    return {
      sum,
      ...toRefs(person)
    }
  }
}
</script>

<style scoped>

</style>
